{include file="public/header" /}
<style>
    .layui-form-label{width: 180px;margin-left: -55px}
</style>
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>编辑产品</h5>
                </div>
                <div class="ibox-content layui-form">
                    <div class="layui-row layui-col-space10 layui-form-item ">

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md6">
                            <label class="layui-form-label">产品名称_英文：</label>
                            <div class="layui-input-block">
                                <input type="text" name="name_en" value="{$data.goods_name_en}" lay-verify="required" placeholder="产品名称_英文" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md6">
                            <label class="layui-form-label">产品名称_西班牙：</label>
                            <div class="layui-input-block">
                                <input type="text" name="name_es" value="{$data.goods_name_es}" lay-verify="required" placeholder="产品名称_西班牙" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md6">
                            <label class="layui-form-label">产品名称_葡萄牙：</label>
                            <div class="layui-input-block">
                                <input type="text" name="name_tp" value="{$data.goods_name_tp}" lay-verify="required" placeholder="产品名称_葡萄牙" class="layui-input">
                            </div>
                        </div>


                        <div class="layui-form-item layui-col-md-offset1 layui-col-md6">
                            <label class="layui-form-label">缩略图：</label>
                            <input type="hidden" name="goods_thumb" id="lay-img" lay-verify="image" value="{$data.goods_thumb}">
                            <div class="layui-input-block">
                                <div id="lay-upload">上传图片</div>
                                <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                                    预览：
                                    <div class="layui-upload-list" id="lay-list">
                                        <img class="layui-append-img" src="{$data.goods_thumb}" onerror="this.src='/static/admin/images/no_img.jpg'">
                                    </div>
                                </blockquote>
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md6">
                            <label class="layui-form-label">原价：</label>
                            <div class="layui-input-block">
                                <input type="text" name="goods_price" value="{$data.goods_price}" lay-verify="required" placeholder="请输入原价，单位：美元" class="layui-input" oninput="value=value.replace(/[^\d.]/g,'')">
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md6">
                            <label class="layui-form-label">售价：</label>
                            <div class="layui-input-block">
                                <input type="text" name="goods_cu_price" value="{$data.goods_cu_price}" lay-verify="required" placeholder="请输入售价，单位：美元" class="layui-input" oninput="value=value.replace(/[^\d.]/g,'')">
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md6">
                            <label class="layui-form-label">选择供应商：</label>
                            <div class="layui-input-block">
                                <select name="supplier_id" lay-search="" lay-verify="required">
                                    <option value=""></option>
                                    {foreach name="supplier" item="vo1"}
                                    <option value="{$vo1.supplier_id}" {$vo1.supplier_id==$data.goods_supplier_id ? 'selected' : ''}>{$vo1.supplier_name}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md6">
                            <label class="layui-form-label">选择属性：</label>
                            <div class="layui-input-block">
                                <select name="goods_attr" lay-search="" lay-verify="required">
                                    <option value=""></option>
                                    {foreach name="attr" item="vo2"}
                                    <option value="{$vo2.attr_id}" {$vo2.attr_id==$data.goods_attr ? 'selected' : ''}>{$vo2.attr_name_en}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md6">
                            <label class="layui-form-label">选择包装：</label>
                            <div class="layui-input-block">
                                <select name="goods_packaging"  xm-select="select1" xm-select-search="" xm-select-search-type="dl">
                                    {foreach name="packaging" item="vo3"}
                                    <option value="{$vo3.packaging_id}" {if in_array($vo3.packaging_id,$pack_arr)}selected{/if}>{$vo3.packaging_name}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md10">
                            <label class="layui-form-label">分类：</label>

                            <div class="layui-input-inline" style="margin-top: 5px">
                                <select name="f_cate" lay-search='' lay-verify="required" id="f_cate" lay-filter="f_cate">
                                    <option value="">---- 请选择一级分类 ----</option>
                                    {foreach name="cate" item="vo"}
                                    <option value="{$vo.cate_id}" {$vo.cate_id==$data.goods_f_cate ? 'selected' : ''}>{$vo.cate_name_en}</option>
                                    {/foreach}
                                </select>
                            </div>

                            <div class="layui-input-inline" style="margin-top: 5px">
                                <select name="s_cate" lay-search="" id="s_cate" lay-filter="s_cate">
                                    <option value="">---- 请选择二级分类 ----</option>
                                    {foreach name="cate2" item="vo"}
                                    <option value="{$vo.cate_id}" {$vo.cate_id==$data.goods_s_cate ? 'selected' : ''}>{$vo.cate_name_en}</option>
                                    {/foreach}
                                </select>
                            </div>

                            <div class="layui-input-inline" style="margin-top: 5px">
                                <select name="t_cate" lay-search="" id="t_cate" lay-filter="t_cate">
                                    <option value="">---- 请选择三级分类 ----</option>
                                    {foreach name="cate3" item="vo"}
                                    <option value="{$vo.cate_id}" {$vo.cate_id==$data.goods_t_cate ? 'selected' : ''}>{$vo.cate_name_en}</option>
                                    {/foreach}
                                </select>
                            </div>

                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8" id="image_1">
                            <label class="layui-form-label">相册：</label>
                            <div class="layui-input-block">
                                <input type="hidden" name="del" id="del2" value="">
                                <input type="hidden" id="hid2" value="{$data.goods_images}">
                                <input type="hidden" name="goods_images" id="photo2" value="{$data.goods_images}">
                                <div id="uploader2" class="container-s">
                                    <div class="queueList">
                                        <div class="placeholder">
                                            <div id="filePicker2"></div>
                                            <p>或将图片拖到这里</p>
                                        </div>
                                    </div>
                                    <div class="statusBar" style="display:none;">
                                        <div class="layui-progress layui-progress-big active-s" lay-showpercent="true">
                                            <div class="layui-progress-bar layui-bg-blue" lay-percent="0%">
                                            </div>
                                            <span></span>
                                        </div>
                                        <div class="info"></div>
                                        <div class="btns">
                                            <div id="goPicker2" class="filePicker2"></div>
                                            <div class="uploadBtn">开始上传</div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md6 form-group">
                            <label class="layui-form-label">产品状态：</label>
                            <div class="layui-input-block">
                                <input type="radio" name="goods_status" value="1" class="layui-input" title="上架" {$data.goods_status==1 ? 'checked' : ''} />
                                <input type="radio" name="goods_status" value="2" class="layui-input" title="下架" {$data.goods_status==2 ? 'checked' : ''} />
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md6 form-group">
                            <label class="layui-form-label">是否推荐：</label>
                            <div class="layui-input-block">
                                <input type="radio" name="goods_recommend" value="1" class="layui-input" title="推荐" {$data.goods_recommend==1 ? 'checked' : ''} />
                                <input type="radio" name="goods_recommend" value="2" class="layui-input" title="不推荐" {$data.goods_recommend==2 ? 'checked' : ''} />
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md6 form-group">
                            <label class="layui-form-label">是否促销：</label>
                            <div class="layui-input-block">
                                <input type="radio" name="goods_cu" value="1" class="layui-input" title="促销" {$data.goods_cu==1 ? 'checked' : ''} />
                                <input type="radio" name="goods_cu" value="2" class="layui-input" title="非促销" {$data.goods_cu==2 ? 'checked' : ''} />
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md6">
                            <label class="layui-form-label">规格名_英文：</label>
                            <div class="layui-input-block">
                                <input type="text" name="spec_en" value="{$data.goods_spec_name_en}" lay-verify="required" placeholder="规格名_英文" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md6">
                            <label class="layui-form-label">规格名_西班牙：</label>
                            <div class="layui-input-block">
                                <input type="text" name="spec_es" value="{$data.goods_spec_name_es}" lay-verify="required" placeholder="规格名_西班牙" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md6">
                            <label class="layui-form-label">规格名_葡萄牙：</label>
                            <div class="layui-input-block">
                                <input type="text" name="spec_tp" value="{$data.goods_spec_name_tp}" lay-verify="required" placeholder="规格名_葡萄牙" class="layui-input">
                            </div>
                        </div>


                        <div id="Inc">
                            {volist name='specs' id='ss'}
                            <div class="layui-form-item layui-col-md-offset1 layui-col-md12">
                                <label class="layui-form-label">规格值：</label>

                                <div class="layui-input-inline">
                                    <div class="layui-input-block" style="margin-left:0px">
                                        <input type="text" name="spec_value[]" value="{$ss.spec_value}" placeholder="规格值" class="layui-input" lay-verify="required" >
                                    </div>
                                </div>

                                <div class="layui-input-inline">
                                    <div class="layui-input-block" style="margin-left:0px">
                                        <input type="text" name="spec_price[]" value="{$ss.spec_price}" placeholder="原价" class="layui-input" lay-verify="required" oninput="value=value.replace(/[^\d.]/g,'')">
                                    </div>
                                </div>

                                <div class="layui-input-inline">
                                    <div class="layui-input-block" style="margin-left:0px">
                                        <input type="text" name="spec_cu_value[]" value="{$ss.spec_cu_price}" placeholder="售价" class="layui-input" lay-verify="required" oninput="value=value.replace(/[^\d.]/g,'')">
                                    </div>
                                </div>
                                {if $key == 0}
                                <i class="fa fa-plus-circle layui-input-inline" style="margin-left:5px;margin-top: 10px;width: 20px;height: 20px;cursor:pointer" id="addSpec"></i>
                                {else /}
                                <i class="fa fa-minus-circle layui-input-inline" style="margin-left:5px;margin-top: 10px;cursor: pointer" onclick="decSpec(this)"></i>
                                {/if}
                            </div>
                            {/volist}
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">产品简介_英文：</label>
                            <div class="layui-input-block">
                                <textarea name="intro_en" class="layui-textarea" style="width: 400px" placeholder="产品简介_英文">{$data.goods_intro_en}</textarea>
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">产品简介_西班牙：</label>
                            <div class="layui-input-block">
                                <textarea name="intro_es" class="layui-textarea" style="width: 400px" placeholder="产品简介_西班牙">{$data.goods_intro_es}</textarea>
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">产品简介_葡萄牙：</label>
                            <div class="layui-input-block">
                                <textarea name="intro_tp" class="layui-textarea" style="width: 400px" placeholder="产品简介_葡萄牙">{$data.goods_intro_tp}</textarea>
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md10">
                            <label class="layui-form-label">产品详情_英文：</label>
                            <div class="layui-input-block" id="LAY_editor_en" lay-verify="editor">
                                <p>{$data.goods_detail_en}</p>
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md10">
                            <label class="layui-form-label">产品详情_西班牙：</label>
                            <div class="layui-input-block" id="LAY_editor_es" lay-verify="editor">
                                <p>{$data.goods_detail_es}</p>
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md10">
                            <label class="layui-form-label">产品详情_葡萄牙：</label>
                            <div class="layui-input-block" id="LAY_editor_tp" lay-verify="editor">
                                <p>{$data.goods_detail_tp}</p>
                            </div>
                        </div>
                        <input type="hidden" value="{$data.goods_id}" name="goods_id">
                        <input type="hidden" value="1" name="spec_change" id="spec_change">

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit="" lay-filter="component-form-element">确定
                                </button>
                                <!--<button class="layui-btn layui-btn-primary" onclick="history.go(-1)">关闭</button>-->
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

{include file="public/footer" /}
<script>
    wk.uploadImg({size:5,type:'png,jpg,jpeg',url:"{:url('Upload/upload')}",domain:""}); // 缩略图

    // 多图
    var n = wk.uploads({attr:2,num:6,type:'png,jpg,jpeg',url:"{:url('admin/upload/upload')}"});
    function imgDel(e,obj){
        wk.uploads_del(e,obj,n); // 删除
    }
    // 富文本
    var editor_en = wk.wang({elem:'#LAY_editor_en'}); // 英文
    var editor_es = wk.wang({elem:'#LAY_editor_es'}); // 西班牙
    var editor_tp = wk.wang({elem:'#LAY_editor_tp'}); // 葡萄牙

    layui.use(['form','upload','layedit','laydate'], function() {
        var form = layui.form;
        form.verify({
            image:[/\S/,'请上传缩略图'],
            images:[/\S/,'请上传产品图集'],
            editor:function(value,item){
                if(!editor_en.txt.text()){
                    return '请填写英文产品详情';
                }
                if(!editor_es.txt.text()){
                    return '请填写西班牙语产品详情';
                }
                if(!editor_tp.txt.text()){
                    return '请填写葡萄牙语产品详情';
                }
            }
        });
        // 创建订单
        form.on('submit(component-form-element)', function (data) {
            data.field.detail_en = editor_en.txt.html();
            data.field.detail_es = editor_es.txt.html();
            data.field.detail_tp = editor_tp.txt.html();
           $('.layui-btn').addClass('layui-disabled').attr('disabled','disabled');
            $.ajax({
                url:"{:url('goodsEdit')}",
                type:'post',
                dataType:'json',
                data:data.field,
                success:function(res){
                    if (res.code == 200) {
                        layer.msg(res.msg,{icon:1,time:1500,shade:0.1},function(index){
                            wk.layer_close();
                        });
                    } else {
                       wk.error(res.msg,'','$(".layui-btn").removeClass(\'layui-disabled\').removeAttr(\'disabled\');');
                    }
                }
            });
        });

    });
</script>
<script>
    // 添加规格值
    $('#addSpec').click(function () {
        var _spec = '';
        _spec += '<div class="layui-form-item layui-col-md-offset1 layui-col-md12">';
        _spec += '<label class="layui-form-label"></label>';
        _spec += '<div class="layui-input-inline">';
        _spec += '<div class="layui-input-block" style="margin-left:0px">';
        _spec += '<input type="text" name="spec_value[]" placeholder="规格值" class="layui-input" lay-verify="required">';
        _spec += '</div>';
        _spec += '</div>';
        _spec += '<div class="layui-input-inline">';
        _spec += '<div class="layui-input-block" style="margin-left:0px">';
        _spec +='<input type="text" name="spec_price[]" placeholder="原价" class="layui-input" lay-verify="required" onInput="value=value.replace(/[^\\d.]/g,\'\')">';
        _spec += '</div>';
        _spec += '</div>';
        _spec += '<div class="layui-input-inline">';
        _spec += '<div class="layui-input-block" style="margin-left:0px">';
        _spec += '<input type="text" name="spec_cu_value[]" placeholder="售价" class="layui-input" lay-verify="required" onInput="value=value.replace(/[^\\d.]/g,\'\')">';
        _spec += '</div>';
        _spec += '</div>';
        _spec += '<i class="fa fa-minus-circle layui-input-inline" style="margin-left:5px;margin-top: 10px;cursor: pointer" onclick="decSpec(this)"></i>';
        _spec += '</div>';
        $('#Inc').append(_spec);
        $('#spec_change').val(2);
    });
    
    // 删除订单产品
    function decSpec(_this) {
        _this.closest('div').remove();
        $('#spec_change').val(2);
    }
</script>


</body>
</html>